﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ImagePoof
{
    public partial class frmQueue : Form
    {
        private frmPoof parent;

        public frmQueue(frmPoof poof)
        {
            InitializeComponent();
            parent = poof;
        }

        private void lstQueue_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop, false) == true)
                e.Effect = DragDropEffects.All;
        }

        private void lstQueue_DragDrop(object sender, DragEventArgs e)
        {
            string[] tmp = (string[])e.Data.GetData(DataFormats.FileDrop);
            string[] tmp2 = PoofLib.RemoveNonImages(tmp);

            if (tmp2.Length != 0)
            {
                for (int x = 0; x < tmp2.Length; x++)
                {
                    if (!lstQueue.Items.Contains(tmp2[x]))
                        lstQueue.Items.Add(tmp2[x]);
                }
                parent.appargs = new string[lstQueue.Items.Count];
                for (int x = 0; x < lstQueue.Items.Count; x++)
                    parent.appargs[x] = lstQueue.Items[x].ToString();
                parent.Text = "Poof! " + lstQueue.Items.Count + " Images Loaded";
            }
        }

        private void frmQueue_Load(object sender, EventArgs e)
        {
            lstQueue.Items.Clear();
            if (parent.appargs.Length == 0)
                return;
            for (int x = 0; x < parent.appargs.Length; x++)
            {
                lstQueue.Items.Add(parent.appargs[x]);
            }
        }

        private void btnRemoveFromQueue_Click(object sender, EventArgs e)
        {
            int i = lstQueue.SelectedIndex;
            if (i == -1)
                return;

            lstQueue.Items.RemoveAt(i);
            if (lstQueue.Items.Count == 0)
                parent.appargs = new string[] { };
            else
            {
                parent.appargs = new string[lstQueue.Items.Count];
                for (int x = 0; x < lstQueue.Items.Count; x++)
                {
                    parent.appargs[x] = lstQueue.Items[x].ToString();
                }
            }

            parent.Text = "Poof! " + lstQueue.Items.Count + " Images Loaded";
        }

        private void lstQueue_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Delete)
                btnRemoveFromQueue_Click(sender, e);
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
